package com.ming_za.odupdaterserver.core.controller.cmd;

import com.ming_za.odupdaterserver.core.controller.web.AccountAPI;
import com.ming_za.odupdaterserver.core.mco_core.API.CmdOperate;
import com.ming_za.odupdaterserver.core.mco_core.Cmd.BasisCmd.ConfirmCmd;
import com.ming_za.odupdaterserver.core.mco_core.Cmd.CmdCreate;
import com.ming_za.odupdaterserver.core.utils.Msg;

@CmdCreate(cmd = "unlock",explain = "解除验证锁定")
public class UnloadCmd implements CmdOperate {

    private final ConfirmCmd confirmCmd;
    private final Msg msg;
    private final AccountAPI accountAPI;

    public UnloadCmd(ConfirmCmd confirmCmd, Msg msg, AccountAPI accountAPI) {
        this.confirmCmd = confirmCmd;
        this.msg = msg;
        this.accountAPI = accountAPI;
    }

    @Override
    public boolean onCommand(String command, String[] args) {

        if (!accountAPI.isFLocked()){
            msg.soutMsg("&a当前没有锁定");
            return true;
        }

        msg.soutMsg("&e如果是意外锁定请检查服务器安全后再解锁！");
        confirmCmd.addConfirm(unused->{
            accountAPI.unLockLogin();
            msg.info("&a[登录验证]锁定已解除！");
        });

        return true;
    }
}
